package com.ruoyi.stuclient.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.stuclient.domain.EwcCourseGrouping;
import com.ruoyi.stuclient.domain.EwcStudent;
import com.ruoyi.stuclient.domain.vo.GroupSubmitAnalysisVo;
import com.ruoyi.stuclient.domain.vo.StudentGroupCountVo;
import com.ruoyi.stuclient.domain.vo.StudentGroupSubmitVo;
import com.ruoyi.stuclient.service.IEwcStudentGroupService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * 课程分组Controller
 * 
 * @author zsp
 * @date 2025-05-24
 */
@RestController
@RequestMapping("/api/grouping")
public class EwcCourseGroupingController extends BaseController
{
    @Autowired
    private IEwcStudentGroupService iEwcStudentGroupService;

    /**
     * 获取学生分组列表
     * @return AjaxResult
     */
    @Operation(summary = "获取学生分组列表")
    @GetMapping("/getStudentGroupList")
    public AjaxResult getStudentGroupList(@NotNull(message = "章节Id不能为空") String chapterId,
                                          @NotBlank(message = "课程Id不能为空") String courseId,
                                          @NotBlank(message = "班级Id不能为空") String classId) {
        List<StudentGroupCountVo> StudentGroupCountVoList = iEwcStudentGroupService.getStudentGroupList(chapterId,courseId,classId);
        return AjaxResult.success("查询成功", StudentGroupCountVoList);
    }

    /**
     * 获取学生分组详情
     * @param groupingId
     * @return AjaxResult
     */
    @Operation(summary = "获取学生分组详情")
    @GetMapping("/getStudentGroupSubmitInfo")
    public AjaxResult getStudentGroupSubmitInfo(@NotBlank(message = "分组Id不能为空") String groupingId) {
        StudentGroupSubmitVo studentGroupSubmitVo = iEwcStudentGroupService.getStudentGroupSubmitInfo(groupingId);
        return AjaxResult.success("查询成功", studentGroupSubmitVo);
    }

    /**
     * 小组练习提交
     * @param ewcCourseGrouping
     * @return AjaxResult
     */
    @Operation(summary = "小组练习提交")
    @PostMapping("/groupPracticeSubmit")
    public AjaxResult groupPracticeSubmit(@RequestBody EwcCourseGrouping ewcCourseGrouping) {
        boolean result = iEwcStudentGroupService.updateBySIDAndGID(ewcCourseGrouping);
        if(result){
            return AjaxResult.success("提交成功");
        }else {
            return AjaxResult.error("提交失败");
        }
    }

    /**
     * 获取学生分组AI解析详情
     * @param groupingId
     * @param studentId
     * @return AjaxResult
     */
    @Operation(summary = "获取学生分组AI解析详情")
    @GetMapping("/getGroupSubmitAnalysisInfo")
    public AjaxResult getGroupSubmitAnalysisInfo(@NotBlank(message = "分组Id不能为空") String groupingId,
                                                @NotBlank(message = "学生Id不能为空") String studentId) {
        GroupSubmitAnalysisVo groupSubmitAnalysisVo = iEwcStudentGroupService.getGroupSubmitAnalysisInfo(groupingId,studentId);
        return AjaxResult.success("查询成功", groupSubmitAnalysisVo);
    }
}
